Skip to content

Pre-release review fixes: socket and websocket - #21

Merged
leehack merged 3 commits into
mainfrom
fix/review-socket-websocket
Nov 3, 2026
Merged

leehack merged 3 commits into
mainfrom
fix/review-socket-websocket

Conversation

@leehack

@leehack leehack commented Nov 3, 2026 •

Copy link
Copy Markdown
Owner

Fixes four pre-release audit findings in utcp_socket and utcp_websocket. Follow-up to #4.

  • utcp_socket: response_byte_format again accepts every name 0.1.1 accepted through Encoding.getByName (us, cp367, ibm367, csascii, iso646-us, iso-ir-6, ansi_x3.4-1968, csisolatin1, ibm819, iso-ir-100, iso_8859-1:1987, csutf8, …), plus Python's remaining aliases for those charsets. Lookup now ignores every non-alphanumeric character, so names with . and : resolve as they do in Python.
  • utcp_socket CHANGELOG: the str() request format change is marked Breaking: ({n: 1, flag: true} sends 1 True, not 1 true).
  • utcp_websocket: if a URL variable resolves to an insecure address (${WS_URL} → ws://evil.example/ws), registerManual now returns a failed RegisterManualResult and calls throw UtcpSecurityException. Before this, both threw a FormatException. A literal insecure URL in a document still fails at parse time.
  • utcp_websocket CHANGELOG: the parse-time check is marked Breaking: (ws://${HOST}:8765/ws with HOST=localhost now fails at client creation, as in Python). The inaccurate "the check when connecting stays" is gone.

Where the WebSocket URL check runs

flowchart TD
  A[Document parsed: WebSocketCallTemplate.fromJson] --> B{Literal scheme in url?}
  B -- "no, e.g. ${WS_URL}" --> C[Accepted for now]
  B -- yes --> D{"wss://, or ws:// to loopback,<br/>with each ${VAR} read as remote?"}
  D -- no --> E["FormatException at parse:<br/>client creation fails"]
  D -- yes --> C
  C --> F[Client substitutes variables and re-parses]
  F --> G{Substituted url secure?}
  G -- no, discovery --> H["RegisterManualResult.failure<br/>(new: was thrown)"]
  G -- no, tool call --> I["UtcpSecurityException<br/>(new: was FormatException)"]
  G -- yes --> J[Connect: ensureSecureWebSocketUrl<br/>also covers templates built in code]
Loading

How

  • The check now throws InsecureWebSocketUrlException, which is both a FormatException (so document parsing still fails) and a UtcpSecurityException (so a refused call fails like any other security rejection). It is not exported: the package hides it.
  • In utcp, UtcpClient catches a FormatException from the substitute-and-reparse step during discovery and returns RegisterManualResult.failure instead of throwing. This applies to every transport, so it lives in utcp; the websocket package cannot see that its input was substituted.
  • Release note: the discovery fix needs the next utcp. utcp's Unreleased section has Breaking: entries, so tool/prepare_release.dart will raise utcp_websocket's utcp constraint past ^0.2.0 when utcp is bumped to a new minor.

Verification

Every new test fails without its fix: the socket alias test, the utcp client discovery test, and the websocket parse, discovery and call tests. dart format, dart analyze --fatal-infos, and dart test pass in utcp, utcp_socket, utcp_websocket, utcp_conformance and the root.

- utcp_socket: response_byte_format accepts every name 0.1.1 accepted via
  Encoding.getByName; the str() request format change is marked Breaking.
- utcp_websocket: a URL variable resolving to an insecure address fails
  discovery with a result and calls with UtcpSecurityException; the
  parse-time URL check is marked Breaking.
- utcp: registerManual returns a failure when substitution makes the
  manual template invalid.
@leehack
leehack merged commit 0c2fed8 into main Nov 3, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant